package com.sa.web.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import com.sa.web.bean.NewsBean;
import com.sa.web.dao.service.NewsDao;

public class NewsDaoImpl implements NewsDao {
	
	private SqlMapClientTemplate sqlMapClientTemplate;
	
	/**
	 * 增加新闻信息
	 */
	@Override
	public boolean addNews(NewsBean newsBean) {
		return (Integer)sqlMapClientTemplate.insert("addNews", newsBean)>0;
	
	}
	
	@Override
	public Integer getNewsCount() {
		return (Integer) sqlMapClientTemplate.queryForObject("getNewsCount");
	}
	
	@Override
	public List<NewsBean> getNewsInfo(int start, int size) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("start",start);
		map.put("size", size);
		return (List<NewsBean>)sqlMapClientTemplate.queryForList("getNewsInfo", map);
	}
	
	public boolean deleteNewsInfo(String id){
		return sqlMapClientTemplate.delete("deleteNewsInfo",id)>0;
	}
	
	public List<NewsBean> queryNewsIndex(){
		return sqlMapClientTemplate.queryForList("queryNewsIndex");
	}
	
	@Override
	public Integer queryNewsCount() {
		return (Integer) sqlMapClientTemplate.queryForObject("queryNewsCount");
	}
	
	@Override
	public List<NewsBean> queryNews(int currentPage, int pageCounts) {
		Map<String,Integer> map = new HashMap<String,Integer>();
		map.put("start", (currentPage - 1) * pageCounts);
		map.put("end",  currentPage * pageCounts);
		return sqlMapClientTemplate.queryForList("queryNews", map);
	}

	@Override
	public NewsBean queryNewsById(String newsId) {
		return (NewsBean) sqlMapClientTemplate.queryForObject("queryNewsById", newsId);
	}
	
	public SqlMapClientTemplate getSqlMapClientTemplate() {
		return sqlMapClientTemplate;
	}

	public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}
	
	

}
